package html.states.home.notifications;
import data.Message;
import html.util.Container;
import js.Lib;

/**
 * ...
 * @author Felipe Manga
 */

class Dropdown extends Container
{
	var items:Array<Message>;
	static var itemId:Int = 0;
	public function new( parentId:String ) 
	{
		super( parentId + ".dropdown");
		this.items = new Array<Message>();
		this.defaultVisible = false;
	}
	
	@slot function dropdownAddItem( item:Message ):Void
	{
		items.push( item );
		if ( items.length > 10 )
		{
			items.shift();
		}
		
		this.element.innerHTML = "<div id='dropdownItem" + itemId + "'>" + item.renderPreview() + "</div>" + this.element.innerHTML;
		Lib.document.getElementById("dropdownItem" + itemId).addEventListener("click", function( _ ):Void
		{
			this.signalUp("showMessage", [item]);
		});
		itemId++;
	}
	
	@slot function toggleDropdownVisible():Void
	{
		if ( this.visible )
		{
			this.hide();
		}
		else
		{
			this.show();
		}
	}
}